package com.demo.listener;


import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ContextLoaderListener;

public class WebContextListener extends ContextLoaderListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(WebContextListener.class);

    @Override
    public void contextInitialized(ServletContextEvent event) {
        ServletContext context = event.getServletContext();

        String active = context.getInitParameter("spring.profiles.active");
        if("dev".equals(active)){
            LOGGER.info("开发环境");
        }else if("test".equals(active)){
            LOGGER.info("测试环境");
        }else if("pro".equals(active)){
            LOGGER.info("生产环境");
        }else{
            LOGGER.error("环境配置错误!");
        }
    }

}